package com.yzc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.yzc.mapper.AnnouncementMapper;
import com.yzc.model.entity.Announcement.AnnouncementBean;
import com.yzc.model.query.system.AnnouncementReq;
import com.yzc.model.vo.system.AnnouncementVo;
import com.yzc.service.AnnouncementService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, AnnouncementBean>
        implements AnnouncementService {
    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public AnnouncementVo acquireNewAnnouncement() {

        return announcementMapper.acquireNewAnnouncement();
    }

    @Override
    public List<AnnouncementVo> getAllAnnouncement() {
        List<AnnouncementBean> announcementBeans = announcementMapper.selectList(null);
        ArrayList<AnnouncementVo> announcementVos = new ArrayList<>();
        for (AnnouncementBean bean : announcementBeans) {
            AnnouncementVo vo = new AnnouncementVo();
            BeanUtils.copyProperties(bean, vo); // 复制单个对象的属性
            announcementVos.add(vo); // 将复制好的VO对象添加到列表中
        }

        return (announcementVos);
    }

    @Override
    public List<AnnouncementVo> getAnnouncementContent(String content) {
        List<AnnouncementBean> announcementBeans = announcementMapper.getAnnouncementContent(content);
        ArrayList<AnnouncementVo> announcementVos = new ArrayList<>();
        for (AnnouncementBean bean : announcementBeans) {
            AnnouncementVo vo = new AnnouncementVo();
            BeanUtils.copyProperties(bean, vo); // 复制单个对象的属性
            announcementVos.add(vo); // 将复制好的VO对象添加到列表中
        }
        return announcementVos;
    }

    @Override
    public List<AnnouncementVo> loadAnnouncementByUserId(Integer id) {
        return announcementMapper.loadAnnouncementByUserId(id);
    }

    @Override
    public void releaseAnnouncement(AnnouncementReq announcementReq) {
        announcementMapper.releaseAnnouncement(announcementReq);
    }

    @Override
    public void updateAnnouncement(AnnouncementVo announcementVo) {
        announcementMapper.updateAnnouncement(announcementVo);
    }

    @Override
    public void deleteAnnouncementById(Integer id) {
        announcementMapper.deleteById(id);
    }

    @Override
    public List<AnnouncementVo> selectAnnouncement( String content,Integer publisherId) {
        return announcementMapper.selectAnnouncement(content,publisherId );
    }
}
